home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 401-425 / disk_415 / filetypes / filetypese.asm < prev    next >
Assembly Source File  |  1992-05-06  |  11KB  |  502 lines

  1.  
  2. *FileTypes
  3. *written by Sebastian Leske November 1989
  4.  
  5.  
  6.     incdir ":Include/"
  7.     include "libraries/dos_lib.i"
  8.     include "exec/exec_lib.i"
  9.  
  10. *Anfangskram
  11.  
  12.     move.l    d0,ParZL        
  13.     move.l    a0,ParZAdr        
  14.  
  15.     move.l    #0,OldCD        
  16.  
  17.     move.l    #DOSName,a1        
  18.     moveq    #0,d0
  19.     move.l    4,a6
  20.     jsr    _LVOOpenLibrary(a6)
  21.     tst.l    d0
  22.     beq    Ende
  23.     move.l    d0,DOSBase
  24.  
  25.     move.l    DOSBase,a6        
  26.     jsr    _LVOOutput(a6)
  27.     move.l    d0,CurrOut        
  28.  
  29.     jsr    PZAusw            
  30.     tst.l    d0            ;error while processing command line?
  31.     bne    KAuswF            
  32.     moveq.l    #3,d0            ;yes, error #3
  33.     jsr    Fehler            ;report error and end prg
  34.     rts                
  35.  
  36. KAuswF    jsr    EtwasAusg        ;no key character set?
  37.                     ;if so, set all
  38.  
  39. KEAnf    
  40. *Info requested?
  41.     cmpi.l    #2,ParZL        
  42.     bne    DateiZugr    
  43.     move.l    ParZAdr,a0    
  44.     cmpi.b    #"?",(a0)
  45.     bne    DateiZugr    
  46.     bra    Auskunft        ;yes, give info and exit
  47.                     
  48. DateiZugr
  49. *Access file/directory
  50.     lea    Par1,a0            ;Par1=adress of 1st parameter
  51.     move.l    Par1L,d0        ;on command line (set by my comm.
  52.     move.b    #0,0(a0,d0.l)        ;line processor (PZAusw))
  53.     move.l    a0,DatName        
  54.     move.l    a0,d1            
  55.     moveq    #-2,d2            
  56.     move.l    DOSBase,a6        
  57.     jsr    _LVOLock(a6)        
  58.     tst.l    d0            ;entry found?
  59.     bne    VzGef            
  60.     moveq    #0,d0            
  61.     jsr    Fehler            ;no: report error
  62.     bra    DOSzu            ;& exit
  63. VzGef
  64. *entry found
  65.     move.l    d0,DirLock        
  66.     move.l    d0,d1            
  67.     move.l    #InfoBlock,d2        
  68.     jsr    _LVOExamine(a6)        
  69.     tst.l    d0            ;check for error etc.
  70.     bne    ÜbOK        
  71.     moveq    #0,d0        
  72.     jsr    Fehler        
  73.     bra    DOSzu            
  74. ÜbOK    lea    InfoBlock,a0        
  75.     tst.l    4(a0)            
  76.     bpl    Dir            ;type positive=directory
  77.  
  78. Datei1
  79. *1st parameter is a file
  80.     move.l    DatName,d1        
  81.     jsr    DatPrüf            ;check type of file&print it
  82.     bra    DOSzu            ;exit
  83.  
  84. Dir
  85. *1st parameter is a directory
  86.     move.l    DirLock,d1        
  87.     jsr    _LVOCurrentDir(a6)    ;set specified directory as CD
  88.     move.l    d0,OldCD        
  89. DirLoop    move.l    DirLock,d1        
  90.     move.l    #InfoBlock,d2        
  91.     jsr    _LVOExNext(a6)        ;next entry
  92.     tst.l    d0            
  93.     beq    DirEnde            ;none left -> exit
  94.     lea    InfoBlock,a0        
  95.     tst.l    4(a0)            ;a subdirectory?
  96.     bmi    Datei2            
  97.     tst.b    DirS            
  98.     beq    VznAusg            ;if Dir-switch not set, skip dir
  99.     jsr    NamAusg            ;print name of dir
  100.     move.l    CurrOut,d1        
  101.     move.l    #DirText,d2        
  102.     move.l    #12,d3            
  103.     jsr    _LVOWrite(a6)        ;write "*Directory*"
  104. VznAusg    bra    DirLoop            ;go get next entry
  105.  
  106. Datei2
  107. *we've found a file
  108.     move.l    #InfoBlock,d1        
  109.     add.l    #8,d1            
  110.     jsr    DatPrüf            ;check type of file & print it
  111.     bra    DirLoop            ;next entry
  112.  
  113. DirEnde    jsr    _LVOIoErr(a6)
  114.     cmpi.l    #232,d0            ;error No_More_Entries ?
  115.     beq    DOSzu            
  116.     moveq    #2,d0            
  117.     jsr    Fehler            
  118.     bra    DOSzu            
  119.  
  120. DOSzu    move.l    DOSBase,a6
  121.     move.l    OldCD,d1        ;set old CD if it was changed
  122.     tst.l    d1            
  123.     beq    KOldCD            
  124.     jsr    _LVOCurrentDir(a6)    
  125. KOldCD    move.l    DirLock,d1        
  126.     tst.l    d1            
  127.     beq    DZ            
  128.     jsr    _LVOUnLock(a6)        
  129. DZ    move.l    DOSBase,a1        
  130.     move.l    4,a6
  131.     jsr    _LVOCloseLibrary(a6)
  132. Ende    rts                ;THE END
  133.  
  134.  
  135. *give Info (quick reference)
  136. Auskunft
  137.     move.l    DOSBase,a6        
  138.     move.l    CurrOut,d1        
  139.     move.l    #AuskunftText,d2    
  140.     move.l    AuskunftTextL,d3    
  141.     jsr    _LVOWrite(a6)        
  142.     bra    DOSzu            
  143.  
  144. *report error
  145. Fehler
  146.     asl.l    #3,d0            
  147.     lea    FTabelle,a0        
  148.     move.l    0(a0,d0.l),d2        
  149.     move.l    4(a0,d0.l),d3        
  150.     move.l    DOSBase,a6        
  151.     move.l    CurrOut,d1        
  152.     jsr    _LVOWrite(a6)        
  153.     rts                
  154.  
  155. *Test: if no key characters are set, print all types (set switches
  156. *for all types)
  157. EtwasAusg
  158.     tst.b    DirS            
  159.     bne    EtwGes            
  160.     tst.b    UnbS            
  161.     bne    EtwGes            
  162.     tst.b    IFFS
  163.     bne    EtwGes
  164.     lea    PrüfTabelle,a0        
  165. PrüSchl
  166. *test loop
  167.     tst.l    20(a0)            ;switch set to output?
  168.     bne    EtwGes            
  169.     adda.l    #24,a0            
  170.     tst.l    0(a0)            ;end of table?
  171.     bne    PrüSchl            
  172.  
  173.     move.b    #1,DirS            
  174.     move.b    #1,UnbS
  175.     move.b    #1,IFFS
  176.     lea    PrüfTabelle,a0        
  177. SetSchl
  178. *loop to set all output switches to output
  179.     move.l    #1,20(a0)        ;set switch to output
  180.     adda.l    #24,a0    
  181.     tst.l    0(a0)    
  182.     bne    SetSchl    
  183. EtwGes
  184. *at least one key character was found to be set
  185.     rts                ;und zurück
  186.  
  187. *open file and check type
  188. DatPrüf
  189.     move.l    #1005,d2        
  190.     jsr    _LVOOpen(a6)    
  191.     tst.l    d0        
  192.     bne    ÖffnOK        
  193.     moveq    #1,d0        
  194.     jsr    Fehler        
  195.     rts            
  196. ÖffnOK
  197. *no error while opening
  198.     move.l    d0,DatHand        ;read first 50 bytes of file
  199.     move.l    d0,d1            
  200.     move.l    #DateiPuffer,d2        
  201.     move.l    #50,d3            
  202.     jsr    _LVORead(a6)        
  203.     tst.l    d0        
  204.     bpl    LesOK        
  205.     jsr    NamAusg        
  206.     moveq    #1,d0        
  207.     jsr    Fehler        
  208.     move.l    DatHand,d1    
  209.     jsr    _LVOClose(a6)    
  210.     rts            
  211. LesOK    lea    DateiPuffer,a0        
  212.     jsr    CheckDat        ;check first 50 bytes
  213.     move.l    DOSBase,a6
  214.     move.l    DatHand,d1    
  215.     jsr    _LVOClose(a6)    
  216. DatEnd    rts            
  217.  
  218. *check: are contents of buffer an IFF file?
  219. CheckIFF
  220.     moveq    #1,d0            ;
  221.     cmpi.b    #"F",0(a0)        ;
  222.     bne    NoIFF            ;
  223.     cmpi.b    #"O",1(a0)        ;
  224.     bne    NoIFF            ;
  225.     cmpi.b    #"R",2(a0)        ;
  226.     bne    NoIFF            ;
  227.     cmpi.b    #"M",3(a0)        ;
  228.     bne    NoIFF            ;
  229.     rts                ;
  230. NoIFF    moveq    #0,d0            ;return value for "no IFF"
  231. IFFDat    rts                ;
  232.     
  233. *check for known types
  234. CheckDat
  235.     lea    PrüfTabelle,a1        
  236. PrüLoop    move.l    (a1),a2            
  237.     cmp.l    #0,a2            ;end of table of known types?
  238.     beq    TestIFF            ;if so, maybe it's an IFF
  239.     move.l    4(a1),d1    
  240.     move.l    a0,a3        
  241.     add.l    8(a1),a3        
  242. Vergl
  243. *loop: compare one known type with file contents
  244.     move.b    0(a3,d1.l),d0        
  245.     cmp.b    0(a2,d1.l),d0
  246.     bne    Ungl        
  247.     sub.l    #1,d1        
  248.     tst.l    d1        
  249.     bne    Vergl            
  250.  
  251.     tst.l    20(a1)            ;switch for type set?
  252.     beq    TnAusg            ;no, don't print anything
  253.     move.l    a1,-(sp)    
  254.     jsr    NamAusg            ;print file name
  255.     move.l    (sp)+,a1    
  256.     move.l    CurrOut,d1    
  257.     move.l    12(a1),d2    
  258.     move.l    16(a1),d3        
  259.     jsr    _LVOWrite(a6)        ;print type description
  260. TnAusg    rts                
  261.  
  262. Ungl    add.l    #24,a1            ;next entry from table of known
  263.                     ;types
  264.     bra    PrüLoop            
  265.  
  266. TestIFF    bsr    CheckIFF        ;is it an IFF?
  267.     tst.l    d0            
  268.     beq    Unbek            ;no, then we don't know it
  269.     tst.b    IFFS            ;if switch for IFF not set,
  270.     beq    kIFF            ;don't print anything
  271. IFFTest    move.l    a0,a1            
  272.     add.l    #12,a1            
  273.     lea    IFFLücke,a2        
  274.     moveq    #3,d0            
  275. IFFloop    move.b    -(a1),-(a2)        ;copy IFF type (ILBM, 8SVX etc.)
  276.     dbra    d0,IFFloop        ;into type description
  277.     jsr    NamAusg            
  278.     move.l    CurrOut,d1        
  279.     move.l    #IFFText,d2        
  280.     move.w    #IFFTextE-IFFText,d3    
  281.     jsr    _LVOWrite(a6)        ;print type description
  282. kIFF    rts            
  283.  
  284. Unbek
  285. *couldn't identify file
  286.     tst.b    UnbS            ;switch for unknown files set?
  287.     beq    KUnbek        
  288.     jsr    NamAusg        
  289.     move.l    CurrOut,d1    
  290.     move.l    #UnbekText,d2    
  291.     move.l    #20,d3            
  292.     jsr    _LVOWrite(a6)        ;print "Filetype unknown."
  293. KUnbek
  294. *don't mention unknown file
  295.     rts                
  296.  
  297. *print name of file/directory and pad with spaces upto column 30
  298. NamAusg    lea.l    InfoBlock,a5        
  299.     add.l    #8,a5            
  300.     move.l    a5,a0            
  301. LZähl    tst.b    (a0)+            
  302.     bne    LZähl            
  303.     sub.l    #1,a0            
  304.     suba.l    a5,a0            
  305.     move.l    a0,d4            
  306.     move.l    CurrOut,d1        
  307.     move.l    a0,d3            
  308.     move.l    a5,d2            
  309.     move.l    DOSBase,a6
  310.     jsr    _LVOWrite(a6)        ;print name of file/directory
  311.     move.l    #30,d3            ;how many spaces to pad upto
  312.     sub.l    d4,d3            ;column 30?
  313.     move.l    #LeerZ,d2        
  314.     move.l    CurrOut,d1        
  315.     jsr    _LVOWrite(a6)        ;print pad spaces
  316.     rts                
  317.  
  318.  
  319. *CLI command line processing V1.0
  320. *command line must be:Command Parameter1 aParameter2 bParameter3
  321. *cParameter4 dParameter5 etc. aus
  322. *written by Sebastian Leske August/September 1990
  323.  
  324. PZAusw    move.l    ParZAdr,a6        ;Zeiger auf Anf d. P.zeile in a6
  325.     move.l    a6,d7
  326.     add.l    ParZL,d7        ;Endadresse d. Zeile ausrechnen
  327.     subq.l    #1,d7            ;Endadresse korr. (wg. CR am Ende)
  328.  
  329. * 1. Parameter kopieren (ggf. diesen Teil streichen)
  330. *copy 1st parameter (1st parameter has no key character)
  331. LZSpr1    cmpi.b    #32,(a6)+        ;Leerzeichen?
  332.     beq    LZSpr1            ;ja: weiterlesen
  333.     subq    #1,a6            ;Anf.adresse korrigieren
  334.     cmp.l    d7,a6            ;Ende der Eingabe erreicht ?
  335.     bge    AEnde            ;ja, dann beenden
  336.     lea    Par1,a0            ;Pufferadresse holen
  337.     jsr    ParKop            ;Parameter in Puffer kopieren
  338.     move.l    d0,Par1L        ;Länge des 1. Parameters speichern
  339. **??**    jsr    Par1Bearb        ;1. Par. bearbeiten lassen
  340.     cmp.l    d7,a6            ;Ende der Eingabe erreicht ?
  341.     bge    AEnde            ;ja, dann beenden
  342.     
  343. * restliche Parameter (mit Kennbuchstaben) holen
  344. * get the other parameters
  345. ParSu
  346. LZSpr2    cmpi.b    #32,(a6)+        ;Leerzeichen ?
  347.     beq    LZSpr2            ;ja: weiterlesen
  348.     subq    #1,a6            ;Anf.adresse korrigieren
  349.     cmp.l    d7,a6            ;Ende der Eingabe erreicht ?
  350.     bge    AEnde            ;ja, dann beenden
  351.     move.b    (a6),d0            ;gefundenes Zeichen nach d0
  352. **??**    bclr.l    #5,d0            ;Umwandlung in Großbuchstaben
  353.     lea    KennLis,a0        ;Adr. d. Kennbuchstabenliste holen
  354. SuchAP    tst.w    (a0)            ;Listenende erreicht?
  355.     beq    PZFehler        ;ja -> Fehler
  356.     cmp.w    (a0)+,d0        ;Zeichen aus Liste vergleichen
  357.     beq    KennGef            ;Kennbuchstabe gefunden
  358.     addq.l    #4,a0            ;Zeiger auf nächstes Zeichen setzen
  359.     bra    SuchAP            ;weitersuchen
  360. KennGef    move.l    (a0),a5            ;Adresse d. zuständigen UPs holen
  361.     lea    Par,a0            ;Pufferadresse holen
  362.     jsr    ParKop            ;Parameter kopieren
  363.     move.l    d0,ParL            ;Länge des Parameters speichern
  364.     jsr    (a5)            ;AuswertungsUP aufrufen
  365.     cmp.l    d7,a6            ;Ende der Eingabe erreicht ?
  366.     bge    AEnde            ;ja, dann beenden
  367.     bra    ParSu            ;und nächstes Parameter suchen
  368.  
  369. AEnde    moveq.l    #-1,d0            ;kein Fehler aufgetreten (für's HP)
  370.     rts                ;und ENDE
  371.  
  372.  
  373. ***subprogrammes***
  374. *for command line processing
  375.  
  376. ParKop    move.l    #" ",d5            ;Standardtrennzeichen=Leerzeichen
  377.     cmpi.b    #34,(a6)        ;1. Zeichen=Anführungszeichen?
  378.     bne    KAnfz            ;Nein
  379.     move.l    #34,d5            ;ja, Trennzeichen=Anführungszeichen
  380.     addq.l    #1,a6            ;und Zeiger auf nächstes Zeichen
  381. KAnfz    moveq    #-1,d0            ;Längenz. auf 0 (-1 wg. Aufbau d. Schleife)
  382. KopP    move.b    (a6),(a0)+        ;Byte in Puffer kopieren
  383.     addq.l    #1,d0            ;mitzählen...
  384.     cmp.l    d7,a6            ;Ende der Eingabe erreicht?
  385.     bge    ParAE            ;ja, dann Ende
  386.     cmp.b    (a6)+,d5        ;Trennzeichen erreicht?
  387.     bne    KopP            ;nein, dann weiter kopieren        
  388. ParAE    rts                ;und wieder zurück
  389.  
  390. PZFehler
  391.     clr.l    d0            ;0 nach d0 heißt Fehler (für's HP)
  392.     rts                ;und ENDE
  393.  
  394. PZDir    move.b    #1,DirS
  395.     rts
  396.  
  397. PZaP    move.l    #1,PrüfTabelle+20
  398.     rts
  399.  
  400. PZUnb    move.b    #1,UnbS
  401.     rts
  402.  
  403. PZIFF    move.b    #1,IFFS
  404.     rts
  405.  
  406. ***Daten-Bereich***
  407.     SECTION DATA,DATA
  408.  
  409. DOSName    dc.b "dos.library",0
  410.  
  411. FT1    dc.b "Could not access directory/file.",10
  412.     dc.b "Is the pathname correct?",10
  413. FT2    dc.b "Can't read from this file!",10
  414. FT3    dc.b "Error while examining directory!",10
  415. FT4    dc.b "Unknown key character in command line!",10
  416. FTEnde
  417.     cnop 0,4
  418. FTabelle
  419.     dc.l FT1,FT2-FT1
  420.     dc.l FT2,FT3-FT2
  421.     dc.l FT3,FT4-FT3
  422.     dc.l FT4,FTEnde-FT4
  423.  
  424. AuskunftText
  425.     dc.b "FileTypes [Directoryname|Dateiname] [e i d u]",10
  426.     dc.b "FileTypes V2.1",10
  427.     dc.b "© by Sebastian Leske",10
  428.     dc.b "Bergerhauserstr.17a, D-4300 Essen 1",10
  429.     dc.b "This programme may be freely distributed.",10
  430.     dc.b "Length of this executable: 2436 Bytes.",10
  431.     cnop 0,4
  432. AuskunftTextL    dc.l *-AuskunftText
  433.  
  434. DirText        dc.b "*Directory*",10
  435.  
  436.     cnop 0,4
  437. PrüfTabelle    dc.l    aP,3,0,aPText,aPTE-aPText,0
  438.         dc.l    0            ;Endkennung
  439.  
  440. ;format of table (only LWs): 
  441. ;pointer to data that must be compared to recognize type
  442. ;lenght of that data, its position in the file (0=at the very beginning)
  443. ;pointer to text with type description, length of that text,
  444. ;switch for output or no output (set by prg, must be zero)
  445.  
  446. aP    dc.l $3F3
  447.  
  448. aPText    dc.b $9B,"0;32;40m"
  449.     dc.b "Executable file.",10
  450.     dc.b $9B,"0;31;40m"
  451. aPTE
  452.  
  453. IFFText    dc.b "IFF file, type ",$9B,"0;33;40m"     
  454.     ds.b 4                    
  455. IFFLücke dc.b ".",$9B,"0;31;40m",10
  456. IFFTextE
  457.  
  458. UnbekText    dc.b "Filetype unknown.",10
  459.  
  460.     cnop 0,4
  461.  
  462. KennLis    
  463.     dc.w "d"            ;key character
  464.     dc.l PZDir            ;subprg to be called if it's speci-
  465.     dc.w "e"            ;fied in the command line
  466.     dc.l PZaP
  467.     dc.w "u"
  468.     dc.l PZUnb
  469.     dc.w "i"
  470.     dc.l PZIFF
  471.     dc.w 0                ; end of list
  472.  
  473. LeerZ    dc.b "                             "
  474.  
  475. ***Platzbedarfs-Bereich***
  476.     SECTION SPACE,BSS
  477. DOSBase    ds.l 1
  478. ParZAdr    ds.l 1
  479. ParZL    ds.l 1
  480. CurrOut    ds.l 1
  481. DirLock    ds.l 1
  482. OldCD    ds.l 1
  483. DatName    ds.l 1
  484. DatHand    ds.l 1
  485. TestFl    ds.l 1
  486.  
  487. InfoBlock    ds.l 260
  488.  
  489. DateiPuffer    ds.b 50
  490.  
  491. Par1    ds.b 256        ;Speicher für erstes Parameter
  492. Par1L    ds.l 1            ;dessen Länge
  493.  
  494. Par    ds.b 256        ;Zwischenspeicher für sonstige Parameter
  495. ParL    ds.l 1            ;deren jeweilige Länge
  496.         
  497. *switches for print type/don't print type
  498. DirS    ds.b 1
  499. UnbS    ds.b 1
  500. IFFS    ds.b 1
  501.  
  502.